package com.prs.crm.domain.oa;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.BaseEntity;
import com.prs.crm.domain.doc.Document;
import com.prs.crm.domain.hr.Person;

@Entity
@Table(name="oa_jobplan")
public class JobPlan extends BaseEntity{
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String type;
	private String title;
	@ManyToOne
	private Person auditPerson;
	private String state;
	@ManyToOne(fetch = FetchType.LAZY)
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Attachment attach;
	@Lob
	private String summary;
	@OneToOne(fetch=FetchType.LAZY)
	private JobPlan lastJobPlan;
	@ManyToMany(fetch=FetchType.LAZY)
	private Set<Person> copyToPersons;
	@OneToMany(fetch=FetchType.LAZY,mappedBy="jobPlan")
	private Set<JobPlanDetail> jobPlanDetails;
	private Date startTime;
	private Date endTime;
	private Double percent;
	@OneToOne(fetch=FetchType.LAZY,mappedBy="jobPlan")
	private JobPlanAssess jobPlanAssess;
	
	@OneToMany(fetch=FetchType.LAZY,mappedBy="jobPlan")
    private Set<Document> docs;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public Person getAuditPerson() {
		return auditPerson;
	}
	public void setAuditPerson(Person auditPerson) {
		this.auditPerson = auditPerson;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public Attachment getAttach() {
		return attach;
	}
	public void setAttach(Attachment attach) {
		this.attach = attach;
	}
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	public JobPlan getLastJobPlan() {
		return lastJobPlan;
	}
	public void setLastJobPlan(JobPlan lastJobPlan) {
		this.lastJobPlan = lastJobPlan;
	}
	public void setCopyToPersons(Set<Person> copyToPersons) {
		this.copyToPersons = copyToPersons;
	}
	public Set<Person> getCopyToPersons() {
		return copyToPersons;
	}
	public void setJobPlanDetails(Set<JobPlanDetail> jobPlanDetails) {
		this.jobPlanDetails = jobPlanDetails;
	}
	public Set<JobPlanDetail> getJobPlanDetails() {
		return jobPlanDetails;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	public Date getStartTime() {
		return startTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setPercent(Double percent) {
		this.percent = percent;
	}
	public Double getPercent() {
		return percent;
	}
	public void addCopyToPersons(Collection<Person> persons) {
		if(persons!= null) {
			if(copyToPersons == null) {
				copyToPersons = new HashSet<Person>();
			}
			copyToPersons.addAll(persons);
		}
	}
	public void setJobPlanAssess(JobPlanAssess jobPlanAssess) {
		this.jobPlanAssess = jobPlanAssess;
	}
	public JobPlanAssess getJobPlanAssess() {
		return jobPlanAssess;
	}
	public Set<Document> getDocs() {
		return docs;
	}
	public void setDocs(Set<Document> docs) {
		this.docs = docs;
	}
	
}
